<template>
  <div class="OnlinePay">
    <div class="daojishi">
      <p>支付剩余时间</p>
      <van-count-down :time="time" />
    </div>
    <div class="payType">选择支付方式</div>
    <div class="pay_way">
      <div class="pay_item">
        <div class="il">
          <i class="iconfont icon-zhifubao"></i>
          <span>支付宝</span>
        </div>
        <div class="ir">
          <i class="iconfont icon-xuanzhong "
             :class="{'selected':wayindex==0}"
             @click="wayAction($event,0)"></i>
        </div>
      </div>
      <div class="pay_item">
        <div class="il">
          <i class="iconfont icon-weixinzhifu"></i>
          <span>微信</span>
        </div>
        <div class="ir">
          <i class="iconfont icon-xuanzhong"
             :class="{'selected':wayindex==1}"
             @click="wayAction($event,1)"></i>
        </div>
      </div>
    </div>
    <p class="commitPay"
       @click="payAction">确认支付</p>
  </div>
</template>

<script>
import Vue from 'vue';
import { CountDown } from 'vant';
import { Dialog } from 'vant';

Vue.use(CountDown);
export default {
  name: 'OnlinePay',
  data () {
    return {
      time: 1 * 15 * 60 * 1000,
      wayindex: 0,
      arr: [],
    }
  },
  components: {
    [Dialog.Component.name]: Dialog.Component,
  },
  methods: {
    wayAction ($event, n) {
      this.wayindex = n;
    },
    payAction () {
      if (this.wayindex == 0) {
        let nnn = JSON.parse(localStorage.getItem('shop'));
        let mmm = JSON.parse(localStorage.getItem('settlement'));
        console.log(mmm[0].name)

        if (localStorage.getItem('shopinfor')) {
          this.arr = JSON.parse(localStorage.getItem('shopinfor'));
          this.arr.push({ shopname: JSON.parse(localStorage.getItem('shop')).name, shopimg: JSON.stringify(nnn.image_path), zongjia: JSON.parse(localStorage.getItem('waitPay')), diancan: JSON.stringify(mmm[0].name) });
          localStorage.setItem('shopinfor', JSON.stringify(this.arr));
        } else {
          this.arr.push({
            shopname: JSON.parse(localStorage.getItem('shop')).name, shopimg: JSON.stringify(nnn.image_path), zongjia: JSON.parse(localStorage.getItem('waitPay')), diancan: JSON.stringify(mmm[0].name)
          });
          localStorage.setItem('shopinfor', JSON.stringify(this.arr));
        }

        this.$router.push({ name: 'Zhifu' });
      } else {
        // alert('不支持当前支付方式');
        Dialog.alert({
          message: '不支持当前支付方式',
        }).then(() => {
          // on close
        });
      }
    }
  },
}
</script>

<style lang="less">
body {
  background-color: #f5f5f5;
}

.OnlinePay {
  .daojishi {
    background-color: white;
    padding: 16px;
    p {
      font-size: 14px;
      color: #666;
      text-align: center;
      margin-top: 23px;
    }
    .van-count-down {
      font-size: 40px;
      color: #333;
      text-align: center;
      margin: 15px 0 23px;
    }
  }
  .payType {
    background-color: #f1f1f1;
    padding: 0 15px;
    font-size: 16px;
    line-height: 42px;
  }
  .pay_way {
    background-color: white;
    .pay_item {
      padding: 9px 16px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .il {
        i {
          font-size: 35px;
          color: #3190e8;
          margin-right: 10px;
        }
        span {
          font-size: 16px;
          color: #666;
        }
        .icon-weixinzhifu {
          color: #4cd964;
        }
      }
      .ir {
        i {
          font-size: 23px;
        }
        .selected {
          color: #4cd964;
        }
      }
    }
  }
  .commitPay {
    background-color: #4cd964;
    font-size: 16px;
    color: #fff;
    text-align: center;
    font-weight: 700;
    margin: 12px 16px 0px;
    line-height: 42px;
    border-radius: 5px;
  }
}
</style>